package com.example.educationblockchain.service;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.educationblockchain.mapper.*;
import com.example.educationblockchain.model.*;
import com.example.educationblockchain.model.Class;
import com.example.educationblockchain.util.Encrypted;
import com.example.educationblockchain.util.SseEmitterServer;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.java_websocket.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdminInformationService {

    @Autowired
    BlockMapper blockMapper;

    @Autowired
    DataBlockService dataBlockService;

    @Autowired
    P2PService p2PService;

    @Autowired
    AdminLoginMapper adminLoginMapper;

    @Autowired
    CollegeMapper collegeMapper;

    @Autowired
    MajorMapper majorMapper;

    @Autowired
    ClassMapper classMapper;

    @Autowired
    CourseMapper courseMapper;

    @Autowired
    StudentLoginMapper studentLoginMapper;

    Encrypted encrypted = new Encrypted();

    public long insertInformation(Map<String, Object> data) throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Data info = new Data();

        info.setNumber(data.get("number").toString());
        info.setName(data.get("name").toString());
        info.setSex(data.get("sex").toString());
        info.setIdNumber(data.get("idNumber").toString());
        info.setBirth(data.get("birth").toString());
        info.setNation(data.get("nation").toString());
        info.setPlace(data.get("place").toString());
        info.setPostCode(data.get("postCode").toString());
        info.setStatus(data.get("status").toString());
        info.setPhone(data.get("phone").toString());
        info.setMail(data.get("mail").toString());
        info.setStudentType(data.get("studentType").toString());
        info.setStudentProvince(data.get("studentProvince").toString());
        info.setMiddleSchool(data.get("middleSchool").toString());
        info.setDate(data.get("date").toString());
        info.set_class(data.get("_class").toString());
        info.setCollege(data.get("college").toString());
        info.setLevel(data.get("level").toString());
        info.setMajor(data.get("major").toString());

        System.out.println(info);

        Map<String, String> map = encrypted.Encrypt(info);
        System.out.println(map);

        Block block = new Block();

        if (info.get_class() != null) {
            block.set_class(info.get_class());
        }
        if (info.getName() != null) {
            block.setName(info.getName());
        }
        if (info.getNumber() != null) {
            block.setNumber(info.getNumber());
        }
        block.setTimestamp(System.currentTimeMillis());
        block.setC4(map.get("c4"));
        block.setPk(map.get("pk"));
        block.setSk(map.get("sk"));

        long index = blockMapper.selectBlockNum();

        System.out.println(index);


        block.setIndex(index);


        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("_index", index - 1);

        if(index==0){
            block.setPreviousHash("");
        }else {
            block.setPreviousHash(blockMapper.selectOne(wrapper).getHash());
        }

        block.setHash(calculateHash(block));

        wrapper.clear();
        wrapper.eq("id",block.getNumber());
        if(studentLoginMapper.selectList(wrapper).isEmpty()){
            System.out.println("可算进来了");
            StudentLogin studentLogin = new StudentLogin(block.getNumber(),block.getNumber());
            studentLoginMapper.insert(studentLogin);
        }

        blockMapper.insert(block);

        DataBlock dataBlock = new DataBlock(block.getHash(), map.get("c5"));

        dataBlockService.saveDataBlock(dataBlock);

        p2PService.responseNewBlockMsg(block, dataBlock);

        System.out.println(dataBlock);
        System.out.println(block);

        return index;
    }

    public long addInformation(Data data) throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Map<String, String> map = encrypted.Encrypt(data);
        System.out.println(map);

        Block block = new Block();

        if (data.get_class() != null) {
            block.set_class(data.get_class());
        }
        if (data.getName() != null) {
            block.setName(data.getName());
        }
        if (data.getNumber() != null) {
            block.setNumber(data.getNumber());
        }
        block.setTimestamp(System.currentTimeMillis());
        block.setC4(map.get("c4"));
        block.setPk(map.get("pk"));
        block.setSk(map.get("sk"));

        long index = blockMapper.selectBlockNum();

        block.setIndex(index);

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("_index", index - 1);

        if(index==0){
            block.setPreviousHash("");
        }else {
            block.setPreviousHash(blockMapper.selectOne(wrapper).getHash());
        }

        block.setHash(calculateHash(block));

        wrapper.clear();
        wrapper.eq("id",block.getNumber());
        if(studentLoginMapper.selectList(wrapper).isEmpty()){
            StudentLogin studentLogin = new StudentLogin(block.getNumber(),block.getNumber());
            studentLoginMapper.insert(studentLogin);
        }

        blockMapper.insert(block);

        DataBlock dataBlock = new DataBlock(block.getHash(), map.get("c5"));

        dataBlockService.saveDataBlock(dataBlock);

        System.out.println(dataBlock);
        System.out.println(block);

        p2PService.responseNewBlockMsg(block, dataBlock);

        return index;
    }

    public long editData(Map<String, String> map) throws BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, UnsupportedEncodingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Map item = getDataByIndex(Long.parseLong(map.get("index")));
        Data data = (Data) item.get("data");

        data.setNumber(map.get("number").toString());
        data.setName(map.get("name").toString());
        data.setSex(map.get("sex").toString());
        data.setIdNumber(map.get("idNumber").toString());
        data.setBirth(map.get("birth").toString());
        data.setNation(map.get("nation").toString());
        data.setPlace(map.get("place").toString());
        data.setPostCode(map.get("postCode").toString());
        data.setStatus(map.get("status").toString());
        data.setPhone(map.get("phone").toString());
        data.setMail(map.get("mail").toString());
        data.setStudentType(map.get("studentType").toString());
        data.setStudentProvince(map.get("studentProvince").toString());
        data.setMiddleSchool(map.get("middleSchool").toString());
        data.setDate(map.get("date").toString());
        data.set_class(map.get("_class").toString());
        data.setCollege(map.get("college").toString());
        data.setLevel(map.get("level").toString());
        data.setMajor(map.get("major").toString());

        return addInformation(data);
    }

    public Map<String, Object> getInfoList(int pageNum) {
        List<Object> result = new ArrayList<>();
        IPage<Block> blockIPage = new Page<>(pageNum, 10);
        QueryWrapper<Block> blockQueryWrapper = new QueryWrapper<Block>().orderByDesc("_timestamp");
        blockIPage = blockMapper.selectPage(blockIPage,blockQueryWrapper);

        List<Block> blocks = blockIPage.getRecords();

        for (Block block : blocks) {
            Map<String, Object> map = new HashMap<>();
            map.put("index", block.getIndex());
            map.put("name", block.getName());
            map.put("number", block.getNumber());
            map.put("class", block.get_class());
            map.put("time", block.getTimestamp());
            result.add(map);
        }

        Map<String, Object> data = new HashMap<>();

        data.put("blockList",result);
        data.put("maxPage",blockIPage.getPages());


        return data;
    }

    public Map<String, Object> getSearchInfoList(int pageNum,String search) {
        List<Object> result = new ArrayList<>();
        IPage<Block> blockIPage = new Page<>(pageNum, 10);
        QueryWrapper<Block> blockQueryWrapper = new QueryWrapper<Block>().like("number",search).or()
                .like("_name",search).or().like("_class",search).orderByDesc("_timestamp");
        blockIPage = blockMapper.selectPage(blockIPage,blockQueryWrapper);

        List<Block> blocks = blockIPage.getRecords();

        for (Block block : blocks) {
            Map<String, Object> map = new HashMap<>();
            map.put("index", block.getIndex());
            map.put("name", block.getName());
            map.put("number", block.getNumber());
            map.put("class", block.get_class());
            map.put("time", block.getTimestamp());
            result.add(map);
        }

        Map<String, Object> data = new HashMap<>();

        data.put("blockList",result);
        data.put("maxPage",blockIPage.getPages());


        return data;
    }

    public Map<String, Object> getSearchClassInfoList(int pageNum,int id,String search) {
        Class _class = classMapper.selectById(id);



        List<Object> result = new ArrayList<>();
        IPage<Block> blockIPage = new Page<>(pageNum, 10);

        QueryWrapper<Block> blockQueryWrapper = new QueryWrapper<Block>();
        if(search==""){
            blockQueryWrapper.eq("_class",_class.get_name()).orderByDesc("_timestamp");
        }else {
            blockQueryWrapper.like("number",search).or()
                    .like("_name",search).eq("_class",_class.get_name()).orderByDesc("_timestamp");
        }
        blockIPage = blockMapper.selectPage(blockIPage,blockQueryWrapper);

        List<Block> blocks = blockIPage.getRecords();

        for (Block block : blocks) {
            Map<String, Object> map = new HashMap<>();
            map.put("index", block.getIndex());
            map.put("name", block.getName());
            map.put("number", block.getNumber());
            map.put("class", block.get_class());
            map.put("time", block.getTimestamp());
            result.add(map);
        }

        Map<String, Object> data = new HashMap<>();

        data.put("blockList",result);
        data.put("maxPage",blockIPage.getPages());


        return data;
    }

    public Map<String, Object> getDataByIndex(long index) throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Map<String, Object> map = new HashMap<>();

        Block block = new Block();

        Map<String, String> result = new HashMap<>();

        List<String> ws = new ArrayList<>();

        for (WebSocket socket : p2PService.getSockets()) {
            ws.add(socket.getRemoteSocketAddress().toString());
        }

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("_index", index);

        block = blockMapper.selectOne(wrapper);


        List<DataBlock> dataBlocks = dataBlockService.findDataBlockByHash(block.getHash());

        System.out.println(dataBlocks.get(0));

        System.out.println(block);

        Data data = new Data();

        try {
            data = encrypted.Decrypt(block, dataBlocks.get(0).getDataBlock());
            System.out.println(data);
            map.put("error","false");
        } catch (Exception e) {
            System.out.println("粗错了");
            map.put("error","true");
        }


        map.put("data", data);

        wrapper.clear();
        wrapper.eq("number",block.getNumber());

        map.put("maxPage", blockMapper.selectCount(wrapper));

        map.put("page", blockMapper.selectBlockRank(block.getNumber(), block.getIndex()));

        map.put("ws", ws);

        return map;
    }

    public long getDataByPage(Map<String, String> map) throws BadPaddingException, NoSuchPaddingException, NoSuchAlgorithmException, IllegalBlockSizeException, UnsupportedEncodingException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Map<String, Object> result = new HashMap<>();

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("_index", map.get("index"));

        Block block = blockMapper.selectOne(wrapper);

        int page = Integer.parseInt(map.get("page"));

        List<Block> blockList = blockMapper.selectBlocksOrder(block.getNumber());
        block = blockList.get(page - 1);


        return block.getIndex();
    }

    public long addGrade(Map<String, String> grade) throws BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, UnsupportedEncodingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Map item = getDataByIndex(Long.parseLong(grade.get("index")));
        Data data = (Data) item.get("data");

        if (data.getGrades() == null) {
            Map<String, Grade> map = new HashMap<>();
            Grade g = new Grade("1", grade.get("name").toString(), grade.get("credit").toString(), grade.get("type").toString(), grade.get("score").toString(), grade.get("semester").toString());
            map.put("1", g);
            data.setGrades(map);
            return addInformation(data);
        } else {
            Map<String, Grade> map = data.getGrades();
            Grade g = new Grade();
            g.setName(grade.get("name").toString());
            g.setCredit(grade.get("credit").toString());
            g.setType(grade.get("type").toString());
            g.setSemester(grade.get("semester").toString());
            g.setScore(grade.get("score").toString());
            g.setId((map.size() + 1) + "");
            map.put((map.size() + 1) + "", g);
            data.setGrades(map);
            return addInformation(data);
        }
    }

    public long deleteGrade(Map<String, String> num) throws BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, UnsupportedEncodingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Map item = getDataByIndex(Long.parseLong(num.get("index")));
        Data data = (Data) item.get("data");

        String id = num.get("id");
        Map<String, Grade> map = data.getGrades();
        map.remove(id);
        data.setGrades(map);
        return addInformation(data);
    }

    public long editGrade(Map<String, String> grade) throws BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, UnsupportedEncodingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        Map item = getDataByIndex(Long.parseLong(grade.get("index")));
        Data data = (Data) item.get("data");

        Map<String, Grade> map = data.getGrades();
        Grade g = new Grade();
        g.setName(grade.get("name"));
        g.setCredit(grade.get("credit"));
        g.setType(grade.get("type"));
        g.setSemester(grade.get("semester"));
        g.setScore(grade.get("score"));
        g.setId(grade.get("id"));
        map.put(grade.get("id"), g);
        data.setGrades(map);
        return addInformation(data);
    }

    public Map<String, Object> getPeersData() {
        Map<String, Object> result = new HashMap<>();

        List<String> ws = new ArrayList<>();

        for (WebSocket socket : p2PService.getSockets()) {
            ws.add(socket.getRemoteSocketAddress().toString());
        }

        result.put("pwd", p2PService.getPeerPassword());

        result.put("ws", ws);
        return result;
    }

    public Map<String, Object> getCheck() {
        Map<String, Object> result = new HashMap<>();

        List<String> ws = new ArrayList<>();

        for (WebSocket socket : p2PService.getSockets()) {
            ws.add(socket.getRemoteSocketAddress().toString());
        }

        long num = blockMapper.selectBlockNum();

        result.put("ws", ws);

        result.put("num",num);

        return result;
    }

    public long checkBlock(long start, long end) {
        Encrypted encrypted = new Encrypted();

        QueryWrapper wrapper = new QueryWrapper();

        Block preBlock = new Block();

        Block block = new Block();

        wrapper.eq("_index", start);
        preBlock = blockMapper.selectOne(wrapper);

        DataBlock dataBlock = dataBlockService.findDataBlockByHash(preBlock.getHash()).get(0);
        try {
            Data data = encrypted.Decrypt(preBlock, dataBlock.getDataBlock());
            System.out.println(data);
        } catch (Exception e) {
            System.out.println("粗错了");
        }

        for (long i = start + 1; i <= end; i++) {
            System.out.println(i);
            wrapper.clear();
            wrapper.eq("_index", i);
            block = blockMapper.selectOne(wrapper);
            System.out.println(block);
            dataBlock = dataBlockService.findDataBlockByHash(block.getHash()).get(0);
            try {
                Data data = encrypted.Decrypt(block, dataBlock.getDataBlock());
                System.out.println(data);
            } catch (Exception e) {
                System.out.println("粗错了");
                return i;
            }
            String Hash = calculateHash(block);

            if (!block.getPreviousHash().equals(preBlock.getHash())) {
                System.out.println("pre哈希对不上");
                System.out.println(dataBlock.getHash());
                System.out.println(preBlock.getHash());

                return i;
            } else if (!dataBlock.getHash().equals(Hash)) {
                System.out.println("hash出错");

                return i;
            } else {
                System.out.println("没问题");
            }

            preBlock = block;

        }
        return -1;
    }

    public String changePassword(Map<String,String> map){
        String orginPwd = map.get("orginPwd");
        String newPwd = map.get("newPwd");

        Map adminData = (Map) SecurityUtils.getSubject().getPrincipal();
        String id = adminData.get("id").toString();

        AdminLogin adminLogin = adminLoginMapper.selectById(id);
        if(!adminLogin.getPassword().equals(orginPwd)){
            return "pwd error";
        }else {
            adminLogin.setPassword(newPwd);

            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("id", id);
            adminLoginMapper.update(adminLogin,wrapper);
            return "success";
        }
    }

    public String register(Map<String,String> map){
        String account = map.get("account");
        String pwd = map.get("pwd");

        if(adminLoginMapper.selectById(account)!=null){
            return "already has";
        }else {
            AdminLogin adminLogin = new AdminLogin(account,pwd);
            adminLoginMapper.insertAdminLogin(adminLogin);
            return "success";
        }
    }

    public List<College> listCollege(){
        return collegeMapper.selectList(new QueryWrapper<>());
    }

    public String addCollege(Map<String,String> map){
        String name = map.get("name");

        College college = new College();

        college.set_name(name);

        collegeMapper.insert(college);

        return "";
    }

    public String deleteCollege(String index){
        QueryWrapper wrapper = new QueryWrapper();

        wrapper.eq("college",index);

        List<Major> majorList = majorMapper.selectList(wrapper);
        System.out.println(majorList);

        for(Major major:majorList){
            wrapper.clear();
            wrapper.eq("major",major.getId());
            List<Class> classList = classMapper.selectList(wrapper);
            System.out.println(classList);
            for(Class _class:classList){
                wrapper.clear();
                wrapper.eq("id",_class.getId());
                classMapper.delete(wrapper);
            }
            wrapper.clear();
            wrapper.eq("id",major.getId());
            majorMapper.delete(wrapper);
        }
        wrapper.clear();
        wrapper.eq("id",index);
        collegeMapper.delete(wrapper);

        return "";
    }

    public String updateCollege(Map<String,String> map){
        String id = map.get("id");
        String name = map.get("name");

        College college = new College(id,name);


        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        collegeMapper.update(college,wrapper);

        return "";
    }

    public List<Major> getMajor(String index){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("college",index);
        return  majorMapper.selectList(wrapper);
    }

    public String addMajor(Map<String,String> map){
        String name = map.get("name");

        String college = map.get("index");

        Major major =new Major();

        major.set_name(name);

        major.setCollege(college);

        majorMapper.insert(major);

        return "";
    }

    public String deleteMajor(String index){
        QueryWrapper wrapper = new QueryWrapper();

        wrapper.eq("major",index);

        List<Class> classList = classMapper.selectList(wrapper);

        for(Class _class:classList){
            wrapper.clear();
            wrapper.eq("id",_class.getId());
            classMapper.delete(wrapper);
        }
        wrapper.clear();
        wrapper.eq("id",index);
        majorMapper.delete(wrapper);

        return "";
    }

    public String updateMajor(Map<String,String> map){
        String id = map.get("id");
        String name = map.get("name");
        String index = map.get("index");

        Major major = new Major(index,id,name);


        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        majorMapper.update(major,wrapper);

        return "";
    }

    public List<Class> getClass(String index){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("major",index);
        return classMapper.selectList(wrapper);
    }

    public String addClass(Map<String,String> map){
        String name = map.get("name");

        String major = map.get("index");

        Class _class = new Class();

        _class.set_name(name);

        _class.setMajor(major);

        classMapper.insert(_class);

        return "";
    }

    public String deleteClass(String index){
        QueryWrapper wrapper = new QueryWrapper();

        wrapper.eq("id",index);

        classMapper.delete(wrapper);

        return "";
    }

    public String updateClass(Map<String,String> map){
        String id = map.get("id");
        String name = map.get("name");
        String index = map.get("index");

        Class _class = new Class(index,id,name);


        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        classMapper.update(_class,wrapper);

        return "";
    }

    public Map<String,Object> getSelect(){
        Map<String, Object> map = new HashMap<>();

        List<College> colleges = collegeMapper.selectList(new QueryWrapper<>());

        List<Major> majors = majorMapper.selectList(new QueryWrapper<>());

        List<Class> classes = classMapper.selectList(new QueryWrapper<>());

        map.put("colleges",colleges);
        map.put("majors",majors);
        map.put("classes",classes);

        return map;
    }

    public List<Course> listCourse(){
        return courseMapper.selectList(new QueryWrapper<>());
    }

    public String addCourse(Map<String,String> map){
        String name = map.get("name");
        String type = map.get("type");
        double credit = Double.parseDouble(map.get("credit"));

        Course course = new Course();
        course.setCredit(credit);
        course.setType(type);
        course.set_name(name);

        courseMapper.insert(course);

        return "";
    }

    public String deleteCourse(String index){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",index);
        courseMapper.delete(wrapper);

        return "";
    }

    public String updateCourse(Map<String,String> map){
        String id = map.get("id");
        String name = map.get("name");
        String type = map.get("type");
        double credit = Double.parseDouble(map.get("credit"));

        Course course = new Course(id,name,credit,type);


        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        courseMapper.update(course,wrapper);

        return "";
    }

    public Course selectCourse(String index){

        return courseMapper.selectById(index);
    }

    public String getDataFromFile(MultipartFile file) throws IOException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeyException, InvalidKeySpecException {
        List<ExcelData> excelDataList = EasyExcel.read(file.getInputStream())
                .head(ExcelData.class)
                .sheet()
                .doReadSync();
        System.out.println(excelDataList);
        List<Data> dataList = new ArrayList<>();
        Data data = new Data();

        for(ExcelData excelData:excelDataList){
            data.setMajor(excelData.getMajor());
            data.setMail(excelData.getMail());
            data.setPhone(excelData.getPhone());
            data.setPostCode(excelData.getPostCode());
            data.setPlace(excelData.getPlace());
            data.setNumber(excelData.getNumber());
            data.setLevel(excelData.getLevel());
            data.setCollege(excelData.getCollege());
            data.set_class(excelData.get_class());
            data.setDate(excelData.getDate());
            data.setMiddleSchool(excelData.getMiddleSchool());
            data.setStudentProvince(excelData.getStudentProvince());
            data.setStudentType(excelData.getStudentType());
            data.setStatus(excelData.getStatus());
            data.setNation(excelData.getNation());
            data.setBirth(excelData.getBirth());
            data.setIdNumber(excelData.getIdNumber());
            data.setSex(excelData.getSex());
            data.setName(excelData.getName());

            addInformation(data);
        }
        return "";
    }

    public String calculateHash(Block block){
        return encrypted.SHA256(block.getIndex()+block.getPreviousHash()+block.getTimestamp()+block.getName()
        +block.getClass()+block.getNumber()+block.getC4()+block.getPk()+block.getSk());
    }
}
